<template>
  <div class="goodsList">
    <HeaderTitle :title="1"></HeaderTitle>
    <div class="tab">
      <div class="text" v-for="item in navList" :key="item.id" @click="changeContext(item.superCategoryId, item.id)"
        :class="item.id === currentId ? 'active' : ''">{{ item.name }}</div>
    </div>
    <div class="card">
      <div class="card-hd">
        <span>甄选品质，睡眠美学</span>
      </div>
      <div class="content">
        <div class="tm" v-for="item in contentList" :key="item.id" @click="toDetail(item.id)">
          <img class="tm-img" :src="item.listPicUrl">
          <div class="tm-name">
            <img class="preLogo" src="https://yanxuan.nosdn.127.net/static-union/16698631101bcf18.png" alt="">
            {{ item.name }}
          </div>
          <div class="price">
            <span>
              <span class="prefix">到手</span>
              <span style="color: rgb(250,30,50); font-weight:bold">
                <span style="font-size: 12px;">￥</span>
                <span style="font-size: 20px;">{{ item.retailPrice }}</span>
              </span>
            </span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
    
<script lang="ts">
import { defineComponent } from "vue"
import { onMounted } from "vue";
export default defineComponent({
  name: "List",
})
</script>
    
<script lang="ts" setup>
import HeaderTitle from "@/components/HeaderTitle/index.vue"
import { useRoute, useRouter } from "vue-router";
import { getListData } from "@/api/list"
import { ref } from "vue";
const route = useRoute()
let categoryId = route.query.categoryId as any
let subCategoryId = route.query.subCategoryId as any
let categoryType = route.query.categoryType as any
let navList = ref<any>([])
let contentList = ref<any>([])
let currentId = ref('')


// 请求数据
async function getListDatalist() {
  const res = await getListData(categoryId, subCategoryId, categoryType)
  navList.value = res.data.categoryL2List
  // console.log(navList)
  contentList.value = res.data.categoryItems.itemList
  currentId.value = res.data.categoryItems.category.id

}
// 点击导航栏切换内容
function changeContext(id1: number, id2: number) {
  // console.log(111,id1,id2,categoryId)
  categoryId = id1
  subCategoryId = id2
  getListDatalist()
}
// 点击跳转到详情页面
const router = useRouter()
function toDetail(id: number) {
  router.push({
    path: "/goodsDetails",
    query: {
      Id:id
    }

  })
  // console.log(id)
}

onMounted(() => {
  getListDatalist()

})

</script>
    
<style scoped lang="less">
.goodsList {
  background-color: #eee;

  .tab {
    margin-top: 50px;
    display: flex;
    width: 100%;
    height: 30px;
    background-color: #fff;
    flex-wrap: nowrap;
    overflow-x: scroll;

    .text {
      flex: left;
      height: 28px;
      line-height: 30px;
      margin: 0 10px;
      text-align: center;
      font-size: 14px;
      flex-shrink: 0;
      overflow: hidden;

      &.active {
        color: #dd1a21;
        border-bottom: 2.5px solid #dd1a21;
      }
    }
  }

  .card {
    margin-top: 10px;
    background-color: #fff;

    .card-hd {
      display: flex;
      align-items: center;
      flex-direction: column;
      justify-content: center;
      // line-height: 50px;
      height: 55px;
      font-size: 14px;
    }

    .content {
      display: flex;
      flex-wrap: wrap;
      flex-direction: row;
      justify-content: space-between;
      padding: 0 10px;

      //  float:left;
      .tm {
        width: 172.5px;

        // float:left
        // overflow: hidden;
        .tm-img {
          display: block;
          height: 172.5px;
          border-radius: 8px;
        }

        .tm-name {
          margin-top: 6px;
          line-height: 20px;
          text-align: left;
          font-size: 14px;
          font-weight: 500;
          text-overflow: ellipsis;
          overflow: hidden;
          color: #12161C;
          word-break: break-all;
          text-overflow: ellipsis;

          .preLogo {
            width: 15px;
            height: 15px;
            vertical-align: middle;
            margin-right: 2px;
          }
        }

        .price {
          padding: 5px 0;

          .prefix {
            font-size: 12px;
            font-weight: 700;
            color: #fa1e32;
          }
        }
      }
    }
  }
}

::v-deep(.van-tabs__nav) {
  // font-size: 70px;
  margin-top: 45px;
}

::v-deep(.van-tab__text) {
  color: black;
}</style>